package ngames.com.sushitv.temp.Presenter;

import android.os.Handler;
import android.os.Message;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.temp.Interface.AnimeInterface;
import ngames.com.sushitv.temp.Interface.AnimeTaskInterface;
import ngames.com.sushitv.temp.Module.AnimeFactory;


/**
 * Created by edmond on 16-7-28.
 */
public class AnimePresenter implements AnimeTaskInterface {
    private AnimeFactory animeFactory;
    private AnimeInterface view;
    private AppApplication application;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what){
                case 0:
                    view.initingData();
                    view.initedData();
                    break;
                case 1:
                    view.moredData();
                    break;
                case 2:
                    view.refreshedData();
                    break;
            }
        }
    };

    public AnimePresenter(AppApplication application,AnimeFactory animeFactory, AnimeInterface view){
        this.application = application;
        this.animeFactory = animeFactory;
        this.view = view;
    }

    @Override
    public void initData() {
        animeFactory.initData(application,view.getAnimesList(),handler);
    }

    @Override
    public void moreData() {
        view.moreingData();
        animeFactory.moreData(application,view.getAnimesList(),handler,view.getPage());
    }

    @Override
    public void refeshData() {
        view.refreshingData();
        animeFactory.refreshData(application,view.getAnimesList(),handler);
    }
}
